package com.r2coding.music.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import com.r2coding.common.enums.Module;
import com.r2coding.common.enums.OperationType;
import com.r2coding.music.annotation.SysLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import com.r2coding.music.entity.SingerEntity;
import com.r2coding.music.service.SingerService;
import com.r2coding.common.util.PageUtils;
import com.r2coding.common.util.Result;

/**
 * 歌手
 *
 * @author 98k灬
 * @email hk666zx@163.com
 * @date 2022-05-04 20:46:11
 */
@RestController
@RequestMapping("/singer")
public class SingerController {
    @Autowired
    private SingerService singerService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public Result list(@RequestParam Map<String, Object> params){
        PageUtils page = singerService.queryPage(params);
        return Result.ok();
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{singerId}")
    public Result info(@PathVariable("singerId") Integer singerId){
		SingerEntity singer = singerService.getById(singerId);
        return Result.ok();
    }

    /**
     * 保存
     */
    @SysLog(module = Module.MUSIC, operationType = OperationType.INSERT, description = "保存歌手")
    @PreAuthorize("hasAuthority('singer:add')")
    @PostMapping("/save")
    public Result save(@RequestBody SingerEntity singer){
        singer.setDeleted(0);
        singer.setUpdateTime(new Date());
        singer.setCreateTime(new Date());
		singerService.save(singer);
        return Result.ok();
    }

    /**
     * 修改
     */
    @SysLog(module = Module.MUSIC, operationType = OperationType.UPDATE, description = "修改歌手")
    @PreAuthorize("hasAuthority('singer:edit')")
    @PutMapping("/update")
    public Result update(@RequestBody SingerEntity singer){
        singer.setUpdateTime(new Date());
		singerService.updateById(singer);
        return Result.ok();
    }

    /**
     * 删除
     */
    @SysLog(module = Module.MUSIC, operationType = OperationType.DELETE, description = "删除歌手")
    @PreAuthorize("hasAuthority('singer:delete')")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable("id") Integer id){
		singerService.removeById(id);
        return Result.ok();
    }

}
